﻿<Page
    x:Name="pageRoot"
    x:Class="Reference.Apps.SearchView"
    DataContext="{Binding Main, Mode=OneWay, Source={StaticResource VMLocator}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Reference.Apps"
    xmlns:common="using:Reference.Apps.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:ExtensionType="Search">


    <Grid Background="{StaticResource ApplicationPageBackgroundBrush}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid x:Name="resultsPanel" Grid.Row="1">
            <Grid x:Name="typicalPanel">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <GridView
                    x:Name="resultsGridView"
                    AutomationProperties.AutomationId="ResultsGridView"
                    AutomationProperties.Name="Search Results"
                    TabIndex="1"
                    Grid.Row="1"
                    Margin="0,-238,0,0"
                    Padding="110,240,110,46"
                    SelectionMode="None"
                    IsSwipeEnabled="False"
                    IsItemClickEnabled="True" ItemClick="SnippetsListItem_Click"
                    ItemsSource="{Binding SearchResults}" ItemTemplate="{StaticResource WCodeSnippetTemplate}">
                </GridView>
            </Grid>
        </Grid>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
                        Style="{StaticResource MyButtonResource}"
                        VerticalAlignment="Top"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button" Foreground="{StaticResource ApplicationContrastBackgroundBrush}"/>
            <TextBlock x:Uid="W8AppNameTextBlock" x:Name="pageTitle" Text="App Name" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                       IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40" Foreground="{StaticResource ApplicationContrastBackgroundBrush}"/>
            <TextBlock x:Uid="ResultTextBlock" x:Name="resultText" Grid.Column="2" Text="Results for &#x00a0;" IsHitTestVisible="false" Style="{StaticResource SubheaderTextBlockStyle}"
                       TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,0,40" Foreground="{StaticResource ApplicationContrastBackgroundBrush}" />
            <TextBlock x:Name="queryText" Grid.Column="3" Text="{Binding SearchTerm}" IsHitTestVisible="false" Style="{StaticResource SubheaderTextBlockStyle}"
                       TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="10,0,0,40" FontStyle="Italic" />
        </Grid>

        <!-- Loading grid -->
        <Grid Grid.RowSpan="2" Background="{StaticResource ApplicationContrastBackgroundTransparetBrush}" Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibilityConverter}}">
            <Grid Background="{StaticResource ApplicationPageBackgroundBrush}" Height="200">
                <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Horizontal">
                    <ProgressRing IsActive="{Binding IsBusy}" Height="41"  Width="41" />
                    <TextBlock VerticalAlignment="Center" Margin="10,0,0,0" Foreground="{StaticResource ApplicationContrastBackgroundBrush}" Style="{StaticResource SubheaderTextBlockStyle}">Cargando</TextBlock>
                </StackPanel>
            </Grid>
        </Grid>
        <TextBlock
            x:Name="noResultsTextBlock"
            Grid.Row="1"
            Margin="120,50,0,0"
            Visibility="Collapsed"
            Style="{StaticResource SubheaderTextBlockStyle}"
            Text="No results match your search." />

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ResultStates">
                <VisualState x:Name="ResultsFound" />
                <!-- When there are no results, the results panel is replaced with an informational TextBlock -->
                <VisualState x:Name="NoResultsFound">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="resultsGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="noResultsTextBlock" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Page>
